﻿using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCCommon.OAEnums;
using BCDto.Sim.Admin.Admin;
using BCDto.OA.ApplyOrder;
using BCService.OA.ApplyOrder;

namespace BlackCoffeeRESTful.Controllers.Management.OA.ApplyOrder
{
    /// <summary>
    /// OA申请单信息
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class ApplyOrderController : ManagementBaseController
    {
        private readonly IApplyOrderService applyOrderService;

        public ApplyOrderController(IApplyOrderService applyOrderService)
        {
            this.applyOrderService = applyOrderService;
        }

        /// <summary>
        /// 分页获取申请单信息列表
        /// </summary>
        /// <param name="adminId">登录的管理员</param>
        /// <param name="pageIndex">分页页码</param>
        /// <param name="pageSize">分页页数</param>
        /// <param name="ascending">是否升序排</param>
        /// <param name="type">申请类型</param>
        /// <param name="status">申请单审核状态</param>
        /// <param name="isMyApproved">是否我审批的</param>
        /// <param name="isMyCreated">由我发起的</param>
        /// <param name="isCopierToMe">抄送给我的</param>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<ApplyOrderDto>), 200)]
        public IActionResult Query([FromQuery(Name = "admin_id")]long? adminId,
            [FromQuery(Name = "ascending")]bool ascending = false,
            [FromQuery(Name = "type")]OAApplyOrderType? type = null,
            [FromQuery(Name = "status")]OAApplyOrderStatus? status = null,
            [FromQuery(Name = "is_my_Approved")]bool? isMyApproved = null,
            [FromQuery(Name = "is_my_created")]bool? isMyCreated = null,
            [FromQuery(Name = "is_Copier_to_me")]bool? isCopierToMe = null,
            int pageIndex = 1,
            int pageSize = 10)
        {
            if (this.Admin.IsSystemAccount)
            {
                if (adminId.HasValue)
                {
                    return Ok(this.applyOrderService.GetList(new AdminDto { AdminId = adminId.Value }, pageIndex, pageSize, ascending, type, status, isMyApproved, isMyCreated, isCopierToMe));
                }
                return Ok(this.applyOrderService.GetList(new AdminDto { AdminId = 0 }, pageIndex, pageSize, ascending, type, status, isMyApproved, isMyCreated, isCopierToMe));
            }
            return Ok(this.applyOrderService.GetList(this.Admin, pageIndex, pageSize, ascending, type, status, isMyApproved, isMyCreated, isCopierToMe));
        }

        /// <summary>
        /// 查看申请单详情
        /// </summary>
        /// <param name="applyOrderId">申请单Id</param>
        /// <returns></returns>
        [HttpGet("{apply_order_id}")]
        [ProducesResponseType(typeof(ApplyOrderViewDto), 201)]
        public IActionResult Get([FromRoute(Name = "apply_order_id")] long applyOrderId)
        {
            return Ok(this.applyOrderService.GetDetail(this.Admin, applyOrderId));
        }
    }
}
